<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>{{ codeBookDetail.name }}({{ codeLine }})-借阅记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <SearchModle dataKey="bookCodeHistory" @searchFn="searchFn"></SearchModle>
        <!--本体列表，数据 -->
        <div class="table-body">
          <div class="table-body-box">
            <el-table
                ref="multipleTable"
                :data="arryList"
                :stripe="tableStyle.tableStripe"
                :border="tableStyle.tableBorder"
                tooltip-effect="dark"
                style="width: 100%"
                header-cell-class-name="table-text-c"
                cell-class-name="table-text-c">
              <el-table-column
                  prop="book_name"
                  label="图书名称">
                <template slot-scope="scope">
                  <span>{{ scope.row.book.name }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  prop="code"
                  label="条形码"
                  width="200">
              </el-table-column>
              <el-table-column
                  label="借阅人员">
                <template slot-scope="scope">
                  <span>{{ scope.row.examine ? scope.row.examine.realname : '' }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="借阅时间"
                  width="110">
                <template slot-scope="scope">
                  <!--状态0申请中1待归还2已归还-->
                  <!--<span>{{scope.row.create_time}}</span>-->
                  <!--<span>{{scope.row.examine_time}}</span>-->
                  <span v-show="scope.row.status==0">申请中</span>
                  <span v-show="scope.row.status==1">{{ scope.row.examine_time }}</span>
                  <span
                      v-show="scope.row.status==2">{{ scope.row.examine_time }} 至 {{ scope.row.actual_return_time }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="图书状态"
                  width="80">
                <template slot-scope="scope">
                  <!--<span :class="scope.row.is_borrow==1?'canborrow':'notborrow'">{{scope.row.is_borrow==1?'待还':'已还'}}</span>-->
                  <span v-show="scope.row.status==0">申请中</span>
                  <span v-show="scope.row.status==1">待还书</span>
                  <span v-show="scope.row.status==2">已归还</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!--工具条 分页-->
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              layout="prev, pager, next"
              :total="page.total"
              :page-size="page.pagesize"
              @current-change="handleSizeChange">
          </el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {pagination, yearDay, tableoption} from '@/utils/util.js'
import api from '@/utils/api.js'
import codeHistoryList from "./codeHistoryList";

export default {
  props: ['visible', 'codeBookDetail', 'codeLine'],
  components: {
    codeHistoryList
  },
  data() {
    return {
      dialogVisible: false,
      tableStyle: tableoption,
      arryList: [], // 数据列表
      // 页数searchForm
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      searchForm: {}
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.InitFn()
      }else{
        this.arryList = [];
      }
    }
  },
  created() {
  },

  methods: {
    // 初始化
    async InitFn() {
      this.searchForm.code = this.codeLine;
      this.searchForm.status = 1;
      this.searchForm.p = this.page.pageindex;
      let data = await this.$fetch(this.api.admin_read_index, this.searchForm);
      console.log('data:', data)
      if (!data.code) {
        // create_time
        for (let i in data.list.data) {
          data.list.data[i].create_time = data.list.data[i].create_time.split(' ')[0]
          if (data.list.data[i].status !== 0) {
            data.list.data[i].examine_time = data.list.data[i].examine_time.split(' ')[0]
          }
          if (data.list.data[i].status === 2) {
            data.list.data[i].actual_return_time = data.list.data[i].actual_return_time.split(' ')[0]
          }
        }
        this.arryList = data.list.data
        this.page.total = data.list.total
      } else {
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 搜索组件
    searchFn(option) {
      this.page.pageindex = 1
      this.searchForm = option
      this.InitFn()
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 75%;
  height: 80%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 0 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}
</style>


